Overview | Package | Class | Tree | Deprecated | Index | Help Java Platform
1.1.7
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Class com.sun.java.swing.JComponent

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--com.sun.java.swing.JComponent
Subclasses:
AbstractButton, JComboBox, JInternalFrame.JDesktopIcon, JInternalFrame, JLabel, JLayeredPane, JList, JMenuBar, JOptionPane, JPanel, JPopupMenu, JProgressBar, JRootPane, JScrollBar, JScrollPane, JSeparator, JSlider, JSplitPane, JTabbedPane, JTable, JTableHeader, JTextComponent, JToolBar, JToolTip, JTree, JViewport

public abstract class JComponent
extends java.awt.Container
implements java.io.Serializable
The base class for the Swing components. JComponent provides: For more information on these subjects, see the Swing package description

Warning: serialized objects of this class will not be compatible with future swing releases. The current serialization support is appropriate for short term storage or RMI between Swing1.0 applications. It will not be possible to load serialized Swing1.0 objects with future releases of Swing. The JDK1.2 release of Swing will be the compatibility baseline for the serialized form of Swing objects.

See Also:
KeyStroke, Action, setBorder, registerKeyboardAction, JOptionPane, setDebugGraphicsOptions, setToolTipText, setAutoscrolls, Serialized Form

Inner Class Summary
JComponent.AccessibleJComponent
          Inner class of JComponent used to provide default support for accessibility.
 
Field Summary
AccessibleContext accessibleContext
          --- Accessibility Support --- JComponent will contain all of the methods in interface Accessible, though it won't actally implement the interface - that will be up to the individual objects which extend JComponent.
EventListenerList listenerList
           
static java.lang.String TOOL_TIP_TEXT_KEY
          The comment to display when the cursor is over the component, also known as a "value tip", "flyover help", or "flyover label".
com.sun.java.swing.plaf.ComponentUI ui
           
static int UNDEFINED_CONDITION
          Constant used by some of the apis to mean that no condition is defined.
static int WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
          Constant used for registerKeyboardAction() which means that the comand should be invoked when the receiving component is an ancestor of the focused component or is itself the focused component.
static int WHEN_FOCUSED
          Constant used for registerKeyboardAction() which means that the command should be invoked when the component has the focus.
static int WHEN_IN_FOCUSED_WINDOW
          Constant used for registerKeyboardAction() which means that the command should be invoked when the receiving component is in the window that has the focus or is itself the focused component.
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
JComponent()
          Default JComponent constructor.
 
Method Summary
void addAncestorListener(AncestorListener listener)
          Registers listener so that it will receive AncestorEvents when it or any of its ancestors move or are made visible / invisible.
void addNotify()
          Notification to this component that it now has a parent component.
void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Add a PropertyChangeListener to the listener list.
void addVetoableChangeListener(java.beans.VetoableChangeListener listener)
          Add a VetoableChangeListener to the listener list.
void computeVisibleRect(java.awt.Rectangle visibleRect)
          Returns the Component's "visible rect rectangle" - the intersection of the visible rectangles for this component and all of its ancestors.
boolean contains(int x, int y)
          Give the UI delegate an opportunity to define the precise shape of this component for the sake of mouse processing.
JToolTip createToolTip()
          Returns the instance of JToolTip that should be used to display the tooltip.
void firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
          Support for reporting bound property changes.
void firePropertyChange(java.lang.String propertyName, byte oldValue, byte newValue)
           
void firePropertyChange(java.lang.String propertyName, char oldValue, char newValue)
           
void firePropertyChange(java.lang.String propertyName, short oldValue, short newValue)
           
void firePropertyChange(java.lang.String propertyName, int oldValue, int newValue)
           
void firePropertyChange(java.lang.String propertyName, long oldValue, long newValue)
           
void firePropertyChange(java.lang.String propertyName, float oldValue, float newValue)
           
void firePropertyChange(java.lang.String propertyName, double oldValue, double newValue)
           
void firePropertyChange(java.lang.String propertyName, boolean oldValue, boolean newValue)
           
void fireVetoableChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
          Support for reporting constrained property changes.
AccessibleContext getAccessibleContext()
          Get the AccessibleContext associated with this JComponent
java.awt.event.ActionListener getActionForKeyStroke(KeyStroke aKeyStroke)
          Return the object that will perform the action registered for a given keystroke.
float getAlignmentX()
           
float getAlignmentY()
           
boolean getAutoscrolls()
          Returns true if this component automatically scrolls its contents when dragged, (when contained in a component that supports scrolling, like JViewport
Border getBorder()
          Returns the border of this component or null if no border is currently set.
java.awt.Rectangle getBounds(java.awt.Rectangle rv)
          Store the bounds of this component into "return value" rv and return rv.
java.lang.Object getClientProperty(java.lang.Object key)
          Returns the value of the property with the specified key.
java.awt.Graphics getComponentGraphics(java.awt.Graphics g)
          Returns the graphics object used to paint this component.
int getConditionForKeyStroke(KeyStroke aKeyStroke)
          Return the condition that determines whether a registered action occurs in response to the specified keystroke.
int getDebugGraphicsOptions()
          Returns the state of graphics debugging.
java.awt.Graphics getGraphics()
          Returns this component's graphics context, which lets you draw on a component.
int getHeight()
          Return the current height of this component.
java.awt.Insets getInsets()
          If a border has been set on this component, returns the border's insets, else calls super.getInsets.
java.awt.Point getLocation(java.awt.Point rv)
          Store the x,y origin of this component into "return value" rv and return rv.
java.awt.Dimension getMaximumSize()
          If the maximumSize has been set to a non-null value just return it.
java.awt.Dimension getMinimumSize()
          If the minimumSize has been set to a non-null value just return it.
java.awt.Component getNextFocusableComponent()
          Return the next focusable component or null if the focus manager should choose the next focusable component automatically
java.awt.Dimension getPreferredSize()
          If the preferredSize has been set to a non-null value just return it.
KeyStroke[] getRegisteredKeyStrokes()
          Return the KeyStrokes that will initiate registered actions.
JRootPane getRootPane()
          Returns the JRootPane ancestor for a component
java.awt.Dimension getSize(java.awt.Dimension rv)
          Store the width/height of this component into "return value" rv and return rv.
java.awt.Point getToolTipLocation(java.awt.event.MouseEvent event)
          Return the tooltip location in the receiving component coordinate system If null is returned, Swing will choose a location.
java.lang.String getToolTipText()
          Return the tooltip string that has been set with setToolTipText()
java.lang.String getToolTipText(java.awt.event.MouseEvent event)
          Returns the string to be used as the tooltip for event.
java.awt.Container getTopLevelAncestor()
          Returns the top-level ancestor of this component (either the containing Window or Applet), or null if this component has not been added to any container.
java.lang.String getUIClassID()
          Return the UIDefaults key used to look up the name of the swing.plaf.
java.awt.Rectangle getVisibleRect()
          Returns the Component's "visible rectangle" - the intersection of this components visible rectangle:
 new Rectangle(0, 0, getWidth(), getHeight());
 
and all of its ancestors visible Rectangles.
int getWidth()
          Return the current width of this component.
int getX()
          Return the current x coordinate of the components origin.
int getY()
          Return the current y coordinate of the components origin.
void grabFocus()
          Set the focus on the receiving component.
boolean hasFocus()
          Returns true if this Component has the keyboard focus.
boolean isDoubleBuffered()
          Return whether the receiving component should use a buffer to paint.
boolean isFocusCycleRoot()
          Override this method and return true if your component is the root of of a component tree with its own focus cycle.
boolean isFocusTraversable()
          Identifies whether or not this component can receive the focus.
static boolean isLightweightComponent(java.awt.Component c)
          Returns true if this component is a lightweight, i.e. if it doesn't have a native window system peer.
boolean isManagingFocus()
          Override this method and return true if your JComponent manages focus.
boolean isOpaque()
          Returns true if this component is completely opaque.
boolean isOptimizedDrawingEnabled()
          Returns true if this component tiles its children, i.e. if it can guarantee that the children will not overlap.
boolean isPaintingTile()
          Returns true if the receiving component is currently painting a tile.
boolean isRequestFocusEnabled()
          Return whether the receiving component can obtain the focus by calling requestFocus
boolean isValidateRoot()
          If this method returns true, revalidate() calls by descendants of this component will cause the entire tree beginning with this root to be validated.
void paintBorder(java.awt.Graphics g)
          Paint the component's border.
void paintChildren(java.awt.Graphics g)
          Paint this component's children.
void paintComponent(java.awt.Graphics g)
          If the UI delegate is non-null, call its paint method.
void paintImmediately(int x, int y, int w, int h)
          Paint the specified region in this component and all of its descendants that overlap the region, immediately.
void paintImmediately(java.awt.Rectangle r)
          Paint the specified region now.
void paint(java.awt.Graphics g)
          This method is invoked by Swing to draw components.
void processComponentKeyEvent(java.awt.event.KeyEvent e)
          Process any key events that the component itself recognizes.
void processFocusEvent(java.awt.event.FocusEvent e)
           
void processKeyEvent(java.awt.event.KeyEvent e)
          Override processKeyEvent to process events
void processMouseMotionEvent(java.awt.event.MouseEvent e)
           
void putClientProperty(java.lang.Object key, java.lang.Object value)
          Add an arbitrary key/value "client property" to this component.
void registerKeyboardAction(java.awt.event.ActionListener anAction, java.lang.String aCommand, KeyStroke aKeyStroke, int aCondition)
          Register a new keyboard action.
void registerKeyboardAction(java.awt.event.ActionListener anAction, KeyStroke aKeyStroke, int aCondition)
          Calls registerKeyboardAction(ActionListener,String,KeyStroke,condition) with a null command.
void removeAncestorListener(AncestorListener listener)
          Unregisters listener so that it will no longer receive AncestorEvents

This method will migrate to java.awt.

void removeNotify()
          Notification to this component that it no longer has a parent component.
void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Remove a PropertyChangeListener from the listener list.
void removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
          Remove a VetoableChangeListener from the listener list.
void repaint(long tm, int x, int y, int width, int height)
          Adds the specified region to the dirty region list if the component is showing.
void repaint(java.awt.Rectangle r)
          Adds the specified region to the dirty region list if the component is showing.
boolean requestDefaultFocus()
          Request the focus for the component that should have the focus by default.
void requestFocus()
          Set focus on the receiving component if isRequestFocusEnabled returns true
void resetKeyboardActions()
          Unregister all keyboard actions
void reshape(int x, int y, int w, int h)
          Moves and resizes this component.
void revalidate()
          Support for deferred automatic layout.
void scrollRectToVisible(java.awt.Rectangle aRect)
          Forwards the scrollRectToVisible() message to the JComponent's parent.
void setAlignmentX(float alignmentX)
          Set the value of the alignmentX property.
void setAlignmentY(float alignmentY)
          Set the value of the alignmentY property.
void setAutoscrolls(boolean autoscrolls)
          If true this component will automatically scroll its contents when dragged, if contained in a component that supports scrolling, such as JViewport
void setBorder(Border border)
          Sets the border of this component.
void setBounds(java.awt.Rectangle r)
          Moves and resizes this component.
void setDebugGraphicsOptions(int debugOptions)
          Enables or disables diagnostic information about every graphics operation performed within the component or one of its children.
void setDoubleBuffered(boolean aFlag)
          Set whether the receiving component should use a buffer to paint.
void setMaximumSize(java.awt.Dimension maximumSize)
          Sets the maximumSize of this component to a constant value.
void setMinimumSize(java.awt.Dimension minimumSize)
          Sets the minimumSize of this component to a constant value.
void setNextFocusableComponent(java.awt.Component aComponent)
          Specifies the next component to get the focus after this one, for example, when the tab key is pressed.
void setOpaque(boolean isOpaque)
          If true the components background will be filled with the background color.
void setPreferredSize(java.awt.Dimension preferredSize)
          Set the preferred size of the receiving component. if preferredSize is null, the UI will be asked for the preferred size
void setRequestFocusEnabled(boolean aFlag)
          Set whether the receiving component can obtain the focus by calling requestFocus.
void setToolTipText(java.lang.String text)
          Registers the text to display in a tool tip.
void setUI(com.sun.java.swing.plaf.ComponentUI newUI)
          Set the look and feel delegate for this component.
void setVisible(boolean aFlag)
           
void unregisterKeyboardAction(KeyStroke aKeyStroke)
          Unregister a keyboard action.
void update(java.awt.Graphics g)
          Calls paint(g).
void updateUI()
          Resets the UI property to a value from the current look and feel.
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addNotify, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponentAt, getComponentAt, getComponent, getComponentCount, getComponents, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, paint, paramString, preferredSize, printComponents, print, processContainerEvent, processEvent, removeAll, remove, remove, removeContainerListener, removeNotify, setLayout, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getName, getParent, getPeer, getPreferredSize, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paint, paramString, postEvent, preferredSize, prepareImage, prepareImage, printAll, print, processComponentEvent, processEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait
 

Field Detail

ui

protected com.sun.java.swing.plaf.ComponentUI ui

listenerList

protected EventListenerList listenerList

WHEN_FOCUSED

public static final int WHEN_FOCUSED
Constant used for registerKeyboardAction() which means that the command should be invoked when the component has the focus.

WHEN_ANCESTOR_OF_FOCUSED_COMPONENT

public static final int WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
Constant used for registerKeyboardAction() which means that the comand should be invoked when the receiving component is an ancestor of the focused component or is itself the focused component.

WHEN_IN_FOCUSED_WINDOW

public static final int WHEN_IN_FOCUSED_WINDOW
Constant used for registerKeyboardAction() which means that the command should be invoked when the receiving component is in the window that has the focus or is itself the focused component.

UNDEFINED_CONDITION

public static final int UNDEFINED_CONDITION
Constant used by some of the apis to mean that no condition is defined.

TOOL_TIP_TEXT_KEY

public static final java.lang.String TOOL_TIP_TEXT_KEY
The comment to display when the cursor is over the component, also known as a "value tip", "flyover help", or "flyover label".

accessibleContext

protected AccessibleContext accessibleContext
--- Accessibility Support --- JComponent will contain all of the methods in interface Accessible, though it won't actally implement the interface - that will be up to the individual objects which extend JComponent.
Constructor Detail

JComponent

public JComponent()
Default JComponent constructor. This constructor does no initialization beyond calling the Container constructor, e.g. the initial layout manager is null.
Method Detail

updateUI

public void updateUI()
Resets the UI property to a value from the current look and feel. JComponent subclasses must override this method like this:
   public void updateUI() {
      setUI((SliderUI)UIManager.getUI(this);
   }
  
See Also:
setUI, getLookAndFeel, getUI

setUI

protected void setUI(com.sun.java.swing.plaf.ComponentUI newUI)
Set the look and feel delegate for this component. JComponent subclasses generally override this method to narrow the argument type, e.g. in JSlider:
 public void setUI(SliderUI newUI) {
     super.setUI(newUI);
 }
  

Additionaly JComponent subclasses must provide a getUI method that returns the correct type, e.g.

 public SliderUI getUI() {
     return (SliderUI)ui;
 }
 
See Also:
updateUI, getLookAndFeel, getUI

getUIClassID

public java.lang.String getUIClassID()
Return the UIDefaults key used to look up the name of the swing.plaf.ComponentUI class that defines the look and feel for this component. Most applications will never need to call this method. Subclasses of JComponent that support pluggable look and feel should override this method to return the name of the ComponentUI subclass that defines their look and feel.
Returns:
The name of a ComponentUI subclass.
See Also:
getUI

getComponentGraphics

protected java.awt.Graphics getComponentGraphics(java.awt.Graphics g)
Returns the graphics object used to paint this component. If DebugGraphics is turned on we create a new DebugGraphics object if neccessary otherwise we just configure the specified graphics objects foreground and font.
Returns:
A Graphics object configured for this component

paintComponent

protected void paintComponent(java.awt.Graphics g)
If the UI delegate is non-null, call its paint method. We pass the delegate a copy of the Graphics object to protect the rest of the paint code from irrevocable changes (e.g. Graphics.translate()).
See Also:
paint

paintChildren

protected void paintChildren(java.awt.Graphics g)
Paint this component's children. If shouldUseBuffer is true, no component ancestor has a buffer and the component children can use a buffer if they have one. Otherwise, one ancestor has a buffer currently in use and children should not use a buffer to paint.
See Also:
paint, paint

paintBorder

protected void paintBorder(java.awt.Graphics g)
Paint the component's border.
See Also:
paint, setBorder

update

public void update(java.awt.Graphics g)
Calls paint(g). Doesn't clear the background but see ComponentUI.update() which is called by paintComponent.
Overrides:
update in class java.awt.Container
See Also:
paint, paintComponent, com.sun.java.swing.plaf.ComponentUI

paint

public void paint(java.awt.Graphics g)
This method is invoked by Swing to draw components. Applications should not invoke paint directly, but should instead use the repaint method to schedule the component for redrawing.

This method actually delegates the work of painting to three protected methods: paintComponent, paintBorder, and paintChildren. They're called in the order listed to ensure that children appear on top of component itself. Generally speaking, the component and its children should not paint in the insets area allocated to the border. Subclasses can just override this method, as always. A subclass that just wants to specialize the UI (look and feel) delegates paint method should just override paintComponent.

Overrides:
paint in class java.awt.Container
See Also:
paintComponent, paintBorder, paintChildren, getComponentGraphics, repaint

isPaintingTile

public boolean isPaintingTile()
Returns true if the receiving component is currently painting a tile. If this method returns true, paint will be called again for another tile. This method returns false if you are not painting a tile or if the last tile is painted. Use this method to keep some state you might need between tiles.

isFocusCycleRoot

public boolean isFocusCycleRoot()
Override this method and return true if your component is the root of of a component tree with its own focus cycle.

isManagingFocus

public boolean isManagingFocus()
Override this method and return true if your JComponent manages focus. If your component manages focus, the focus manager will handle your component's children. All key event will be sent to your key listener including TAB and SHIFT+TAB. CONTROL + TAB and CONTROL + SHIFT + TAB will move the focus to the next / previous component.

setNextFocusableComponent

public void setNextFocusableComponent(java.awt.Component aComponent)
Specifies the next component to get the focus after this one, for example, when the tab key is pressed. Invoke this method to override the default focus-change sequence.

getNextFocusableComponent

public java.awt.Component getNextFocusableComponent()
Return the next focusable component or null if the focus manager should choose the next focusable component automatically

setRequestFocusEnabled

public void setRequestFocusEnabled(boolean aFlag)
Set whether the receiving component can obtain the focus by calling requestFocus. The default value is true. Note: Setting this property to false will not prevent the focus manager from setting the focus to this component, it will prevent the component from getting the focus when the focus is requested explicitly. Override isFocusTraversable and return false if the component should never get the focus.

isRequestFocusEnabled

public boolean isRequestFocusEnabled()
Return whether the receiving component can obtain the focus by calling requestFocus
See Also:
#setRequestFocusEnabled()

requestFocus

public void requestFocus()
Set focus on the receiving component if isRequestFocusEnabled returns true
Overrides:
requestFocus in class java.awt.Component

grabFocus

public void grabFocus()
Set the focus on the receiving component. This method is for focus managers, you rarely want to call this method, use requestFocus() enstead.

setPreferredSize

public void setPreferredSize(java.awt.Dimension preferredSize)
Set the preferred size of the receiving component. if preferredSize is null, the UI will be asked for the preferred size

getPreferredSize

public java.awt.Dimension getPreferredSize()
If the preferredSize has been set to a non-null value just return it. If the UI delegates getPreferredSize() method returns a non null then value return that, otherwise defer to the components layout manager.
Returns:
the value of the preferredSize property.
Overrides:
getPreferredSize in class java.awt.Container
See Also:
setPreferredSize

setMaximumSize

public void setMaximumSize(java.awt.Dimension maximumSize)
Sets the maximumSize of this component to a constant value. Subsequent calls to getMaximumSize will always return this value, the components UI will not be asked to compute it. Setting the maximumSize to null restores the default behavior.
See Also:
getMaximumSize

getMaximumSize

public java.awt.Dimension getMaximumSize()
If the maximumSize has been set to a non-null value just return it. If the UI delegates getMaximumSize() method returns a non null value then return that, otherwise defer to the components layout manager.
Returns:
the value of the maximumSize property.
Overrides:
getMaximumSize in class java.awt.Container
See Also:
setMaximumSize

setMinimumSize

public void setMinimumSize(java.awt.Dimension minimumSize)
Sets the minimumSize of this component to a constant value. Subsequent calls to getMinimumSize will always return this value, the components UI will not be asked to compute it. Setting the minimumSize to null restores the default behavior.
See Also:
getMinimumSize

getMinimumSize

public java.awt.Dimension getMinimumSize()
If the minimumSize has been set to a non-null value just return it. If the UI delegates getMinimumSize() method returns a non null value then return that, otherwise defer to the components layout manager.
Returns:
the value of the minimumSize property.
Overrides:
getMinimumSize in class java.awt.Container
See Also:
setMinimumSize

contains

public boolean contains(int x,
                        int y)
Give the UI delegate an opportunity to define the precise shape of this component for the sake of mouse processing.
Returns:
true if this component logically contains x,y.
Overrides:
contains in class java.awt.Component
See Also:
contains(int, int)

setBorder

public void setBorder(Border border)
Sets the border of this component. The Border object is responsible for defining the insets for the component (overriding any insets set directly on the component) and for optionally rendering any border decorations within the bounds of those insets. Borders should be used (rather than insets) for creating both decorative and non-decorative (e.g. margins and padding) regions for a swing component. Compound borders can be used to nest multiple borders within a single component.

This is a bound property.

Parameters:
border - the border to be rendered for this component
See Also:
Border, CompoundBorder

getBorder

public Border getBorder()
Returns the border of this component or null if no border is currently set.
Returns:
the border object for this component
See Also:
setBorder

getInsets

public java.awt.Insets getInsets()
If a border has been set on this component, returns the border's insets, else calls super.getInsets.
Returns:
the value of the insets property.
Overrides:
getInsets in class java.awt.Container
See Also:
setBorder

getAlignmentY

public float getAlignmentY()
Returns:
the value of the alignmentY property.
Overrides:
getAlignmentY in class java.awt.Container
See Also:
setAlignmentY, getAlignmentY

setAlignmentY

public void setAlignmentY(float alignmentY)
Set the value of the alignmentY property.
See Also:
getAlignmentY

getAlignmentX

public float getAlignmentX()
Returns:
the value of the alignmentX property.
Overrides:
getAlignmentX in class java.awt.Container
See Also:
setAlignmentX, getAlignmentX

setAlignmentX

public void setAlignmentX(float alignmentX)
Set the value of the alignmentX property.
See Also:
getAlignmentX

getGraphics

public java.awt.Graphics getGraphics()
Returns this component's graphics context, which lets you draw on a component. Use this method get a Graphics object and then invoke oeprations on that object to draw on the component.
Overrides:
getGraphics in class java.awt.Component

setDebugGraphicsOptions

public void setDebugGraphicsOptions(int debugOptions)
Enables or disables diagnostic information about every graphics operation performed within the component or one of its children. The value of debugOptions determines how the component should display this information: debug is bitwise OR'd into the current value. DebugGraphics.NONE_OPTION disables debugging. A value of 0 causes no changes to the debugging options.

getDebugGraphicsOptions

public int getDebugGraphicsOptions()
Returns the state of graphics debugging.
See Also:
setDebugGraphicsOptions

registerKeyboardAction

public void registerKeyboardAction(java.awt.event.ActionListener anAction,
                                   java.lang.String aCommand,
                                   KeyStroke aKeyStroke,
                                   int aCondition)
Register a new keyboard action. anAction will be invoked if a key event matching aKeyStroke occurs and aCondition is verified. The KeyStroke object defines a particular combination of a keyboard key and one or more modifiers (alt, shift, ctrl, meta).

The aCommand will be set in the delivered event if specified.

The Condition can be one of:

WHEN_FOCUSED
The action will be invoked only when the keystroke occurs while the component has the focus.
WHEN_IN_FOCUSED_WINDOW
The action will be invoked when the keystroke occurs while the component has the focus or if the component is in the window that has the focus. Note that the component need not be an immediate descendent of the window -- it can be anywhere in the window's containment hierarchy. In other words, whenever any component in the window has the focus, the action registered with this component is invoked.
WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
The action will be invoked when the keystroke occurs while the component has the focus or if the component is an ancestor of the component that has the focus.

The combination of keystrokes and conditions lets you define high level (semantic) action events for a specified keystroke+modifier combination (using the KeyStroke class) and direct to a parent or child of a component that has the focus, or to the component itself. In other words, in any hierarchical structure of components, an arbitrary key-combination can be immediately directed to the appropriate component in the hierarchy, and cause a specific method to be invoked (usually by way of adapter objects).

If an action has already been registered for the receiving container, with the same charCode and the same modifiers, anAction will replace the action.

See Also:
KeyStroke

registerKeyboardAction

public void registerKeyboardAction(java.awt.event.ActionListener anAction,
                                   KeyStroke aKeyStroke,
                                   int aCondition)
Calls registerKeyboardAction(ActionListener,String,KeyStroke,condition) with a null command.

unregisterKeyboardAction

public void unregisterKeyboardAction(KeyStroke aKeyStroke)
Unregister a keyboard action.
See Also:
registerKeyboardAction

getRegisteredKeyStrokes

public KeyStroke[] getRegisteredKeyStrokes()
Return the KeyStrokes that will initiate registered actions.
Returns:
an array of KeyStroke objects
See Also:
registerKeyboardAction

getConditionForKeyStroke

public int getConditionForKeyStroke(KeyStroke aKeyStroke)
Return the condition that determines whether a registered action occurs in response to the specified keystroke.
Returns:
the action-keystroke condition
See Also:
registerKeyboardAction

getActionForKeyStroke

public java.awt.event.ActionListener getActionForKeyStroke(KeyStroke aKeyStroke)
Return the object that will perform the action registered for a given keystroke.
Returns:
the ActionListener object invoked when the keystroke occurs
See Also:
registerKeyboardAction

resetKeyboardActions

public void resetKeyboardActions()
Unregister all keyboard actions
See Also:
registerKeyboardAction

requestDefaultFocus

public boolean requestDefaultFocus()
Request the focus for the component that should have the focus by default. The default implementation will recursively request the focus on the first component that is focus-traversable.
Returns:
false if the focus has not been set, otherwise return true

setVisible

public void setVisible(boolean aFlag)
Overrides:
setVisible in class java.awt.Component

isFocusTraversable

public boolean isFocusTraversable()
Identifies whether or not this component can receive the focus. A disabled button, for example, would return false.
Returns:
true if this component can receive the focus
Overrides:
isFocusTraversable in class java.awt.Component

processFocusEvent

protected void processFocusEvent(java.awt.event.FocusEvent e)
Overrides:
processFocusEvent in class java.awt.Component

processComponentKeyEvent

protected void processComponentKeyEvent(java.awt.event.KeyEvent e)
Process any key events that the component itself recognizes. This will be called after the focus manager and any interested listeners have been given a chance to steal away the event. This method will only be called is the event has not yet been consumed. This method is called prior to the keyboard UI logic.

This is implemented to do nothing. Subclasses would normally override this method if they process some key events themselves. If the event is processed, it should be consumed.


processKeyEvent

protected void processKeyEvent(java.awt.event.KeyEvent e)
Override processKeyEvent to process events
Overrides:
processKeyEvent in class java.awt.Component

setToolTipText

public void setToolTipText(java.lang.String text)
Registers the text to display in a tool tip. The text displays when the cursor lingers over the component.

See How to Use Tool Tips in The Java Tutorial for further documentation.

Parameters:
text - The string to display. If the text is null, the tool tip is turned off for this component.
See Also:
TOOL_TIP_TEXT_KEY

getToolTipText

public java.lang.String getToolTipText()
Return the tooltip string that has been set with setToolTipText()
Returns:
the text of the tool tip
See Also:
TOOL_TIP_TEXT_KEY

getToolTipText

public java.lang.String getToolTipText(java.awt.event.MouseEvent event)
Returns the string to be used as the tooltip for event. By default this returns any string set using setToolTipText(). If a component provides more extensize API to support differing tooltips at different locations, this method should be overridden.

getToolTipLocation

public java.awt.Point getToolTipLocation(java.awt.event.MouseEvent event)
Return the tooltip location in the receiving component coordinate system If null is returned, Swing will choose a location. The default implementation returns null.
Parameters:
event - the MouseEvent that caused the ToolTipManager to show the tooltip.

createToolTip

public JToolTip createToolTip()
Returns the instance of JToolTip that should be used to display the tooltip. Components typically would not override this method, but it can be used to cause different tooltips to be displayed differently.

scrollRectToVisible

public void scrollRectToVisible(java.awt.Rectangle aRect)
Forwards the scrollRectToVisible() message to the JComponent's parent. Components that can service the request, such as a JViewport, override this method and perform the scrolling.
See Also:
JViewport

setAutoscrolls

public void setAutoscrolls(boolean autoscrolls)
If true this component will automatically scroll its contents when dragged, if contained in a component that supports scrolling, such as JViewport
See Also:
JViewport, getAutoscrolls

getAutoscrolls

public boolean getAutoscrolls()
Returns true if this component automatically scrolls its contents when dragged, (when contained in a component that supports scrolling, like JViewport
See Also:
JViewport, setAutoscrolls

processMouseMotionEvent

protected void processMouseMotionEvent(java.awt.event.MouseEvent e)
Overrides:
processMouseMotionEvent in class java.awt.Component

getAccessibleContext

public AccessibleContext getAccessibleContext()
Get the AccessibleContext associated with this JComponent
Returns:
the AccessibleContext of this JComponent

getClientProperty

public final java.lang.Object getClientProperty(java.lang.Object key)
Returns the value of the property with the specified key. Only properties added with putClientProperty will return a non-null value.
Returns:
the value of this property or null
See Also:
putClientProperty

putClientProperty

public final void putClientProperty(java.lang.Object key,
                                    java.lang.Object value)
Add an arbitrary key/value "client property" to this component.

The get/putClientProperty methods provide access to a small per-instance hashtable. Callers can use get/putClientProperty to annotate components that were created by another module, e.g. a layout manager might store per child constraints this way. For example:

 componentA.putClientProperty("to the left of", componentB);
 

If value is null this method will remove the property. Changes to client properties are reported with PropertyChange events. The name of the property (for the sake of PropertyChange events) is key.toString().

The clientProperty dictionary is not intended to support large scale extensions to JComponent nor should be it considered an alternative to subclassing when designing a new component.

See Also:
getClientProperty, addPropertyChangeListener

isLightweightComponent

public static boolean isLightweightComponent(java.awt.Component c)
Returns true if this component is a lightweight, i.e. if it doesn't have a native window system peer.

This method will migrate to java.awt.Component in the next major JDK release

Returns:
true if this component is a lightweight

reshape

public void reshape(int x,
                    int y,
                    int w,
                    int h)
Moves and resizes this component.
Overrides:
reshape in class java.awt.Component
See Also:
setBounds

setBounds

public void setBounds(java.awt.Rectangle r)
Moves and resizes this component.
Overrides:
setBounds in class java.awt.Component
See Also:
setBounds

getBounds

public java.awt.Rectangle getBounds(java.awt.Rectangle rv)
Store the bounds of this component into "return value" rv and return rv. If rv is null a new Rectangle is allocated. This version of getBounds() is useful if the caller wants to avoid allocating a new Rectangle object on the heap.
Parameters:
rv - the return value, modified to the components bounds
Returns:
rv
Overrides:
getBounds in class java.awt.Component

getSize

public java.awt.Dimension getSize(java.awt.Dimension rv)
Store the width/height of this component into "return value" rv and return rv. If rv is null a new Dimension object is allocated. This version of getSize() is useful if the caller wants to avoid allocating a new Dimension object on the heap.
Parameters:
rv - the return value, modified to the components size
Returns:
rv
Overrides:
getSize in class java.awt.Component

getLocation

public java.awt.Point getLocation(java.awt.Point rv)
Store the x,y origin of this component into "return value" rv and return rv. If rv is null a new Point is allocated. This version of getLocation() is useful if the caller wants to avoid allocating a new Point object on the heap.
Parameters:
rv - the return value, modified to the components location
Returns:
rv
Overrides:
getLocation in class java.awt.Component

getX

public int getX()
Return the current x coordinate of the components origin. This method is preferable to writing component.getBounds().x, or component.getLocation().x because it doesn't cause any heap allocations.

This method will migrate to java.awt.Component in the next major JDK release

Returns:
the current x coordinate of the components origin.
Overrides:
getX in class java.awt.Component

getY

public int getY()
Return the current y coordinate of the components origin. This method is preferable to writing component.getBounds().y, or component.getLocation().y because it doesn't cause any heap allocations.

This method will migrate to java.awt.Component in the next major JDK release

Returns:
the current y coordinate of the components origin.
Overrides:
getY in class java.awt.Component

getWidth

public int getWidth()
Return the current width of this component. This method is preferable to writing component.getBounds().width, or component.getSize().width because it doesn't cause any heap allocations.

This method will migrate to java.awt.Component in the next major JDK release

Returns:
the current width of this component.
Overrides:
getWidth in class java.awt.Component

getHeight

public int getHeight()
Return the current height of this component. This method is preferable to writing component.getBounds().height, or component.getSize().height because it doesn't cause any heap allocations.

This method will migrate to java.awt.Component in the next major JDK release

Returns:
the current height of this component.
Overrides:
getHeight in class java.awt.Component

hasFocus

public boolean hasFocus()
Returns true if this Component has the keyboard focus.

This method will migrate to java.awt.Component in the next major JDK release

Returns:
true if this Component has the keyboard focus.
Overrides:
hasFocus in class java.awt.Component

isOpaque

public boolean isOpaque()
Returns true if this component is completely opaque.

An opaque component paints every pixel within its rectangular region. A non-opaque component paints only some of its pixels, allowing the pixels underneath it to "show through". A component that does not fully paint its pixels therefore provides a degree of transparency.

Subclasses that guarantee to always completely paint their contents should override this method and return true.

This method will migrate to java.awt.Component in the next major JDK release

Returns:
true if this component is completely opaque.
Overrides:
isOpaque in class java.awt.Component
See Also:
setOpaque

setOpaque

public void setOpaque(boolean isOpaque)
If true the components background will be filled with the background color. Otherwise, the background is transparent, and whatever is underneath will show through.

The default value of this property is false.

This is a JavaBeans bound property.

See Also:
isOpaque

computeVisibleRect

public void computeVisibleRect(java.awt.Rectangle visibleRect)
Returns the Component's "visible rect rectangle" - the intersection of the visible rectangles for this component and all of its ancestors. The return value is stored in visibleRect
See Also:
getVisibleRect

getVisibleRect

public java.awt.Rectangle getVisibleRect()
Returns the Component's "visible rectangle" - the intersection of this components visible rectangle:
 new Rectangle(0, 0, getWidth(), getHeight());
 
and all of its ancestors visible Rectangles.
Returns:
the visible rectangle

firePropertyChange

protected void firePropertyChange(java.lang.String propertyName,
                                  java.lang.Object oldValue,
                                  java.lang.Object newValue)
Support for reporting bound property changes. If oldValue and newValue are not equal and the PropertyChangeEvent listener list isn't empty, then fire a PropertyChange event to each listener. This method has an overloaded method for each primitive type. For example, here's how to write a bound property set method whose value is an int:
 public void setFoo(int newValue) {
     int oldValue = foo;
     foo = newValue;
     firePropertyChange("foo", oldValue, newValue);
 }
 

This method will migrate to java.awt.Component in the next major JDK release

Parameters:
propertyName - The programmatic name of the property that was changed.
oldValue - The old value of the property.
newValue - The new value of the property.
Overrides:
firePropertyChange in class java.awt.Component
See Also:
java.beans.PropertyChangeSupport

firePropertyChange

public void firePropertyChange(java.lang.String propertyName,
                               byte oldValue,
                               byte newValue)
See Also:
firePropertyChange(java.lang.String, java.lang.Object, java.lang.Object)

firePropertyChange

public void firePropertyChange(java.lang.String propertyName,
                               char oldValue,
                               char newValue)
See Also:
firePropertyChange(java.lang.String, java.lang.Object, java.lang.Object)

firePropertyChange

public void firePropertyChange(java.lang.String propertyName,
                               short oldValue,
                               short newValue)
See Also:
firePropertyChange(java.lang.String, java.lang.Object, java.lang.Object)

firePropertyChange

public void firePropertyChange(java.lang.String propertyName,
                               int oldValue,
                               int newValue)
See Also:
firePropertyChange(java.lang.String, java.lang.Object, java.lang.Object)

firePropertyChange

public void firePropertyChange(java.lang.String propertyName,
                               long oldValue,
                               long newValue)
See Also:
firePropertyChange(java.lang.String, java.lang.Object, java.lang.Object)

firePropertyChange

public void firePropertyChange(java.lang.String propertyName,
                               float oldValue,
                               float newValue)
See Also:
firePropertyChange(java.lang.String, java.lang.Object, java.lang.Object)

firePropertyChange

public void firePropertyChange(java.lang.String propertyName,
                               double oldValue,
                               double newValue)
See Also:
firePropertyChange(java.lang.String, java.lang.Object, java.lang.Object)

firePropertyChange

public void firePropertyChange(java.lang.String propertyName,
                               boolean oldValue,
                               boolean newValue)
See Also:
firePropertyChange(java.lang.String, java.lang.Object, java.lang.Object)

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a PropertyChangeListener to the listener list. The listener is registered for all properties.

A PropertyChangeEvent will get fired in response to setting a bound property, e.g. setFont, setBackground, or setForeground. Note that if the current component is inheriting its foreground, background, or font from its container, then no event will be fired in response to a change in the inherited property.

This method will migrate to java.awt.Component in the next major JDK release

Parameters:
listener - The PropertyChangeListener to be added
Overrides:
addPropertyChangeListener in class java.awt.Component

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.

This method will migrate to java.awt.Component in the next major JDK release

Parameters:
listener - The PropertyChangeListener to be removed
Overrides:
removePropertyChangeListener in class java.awt.Component

fireVetoableChange

protected void fireVetoableChange(java.lang.String propertyName,
                                  java.lang.Object oldValue,
                                  java.lang.Object newValue)
                          throws java.beans.PropertyVetoException
Support for reporting constrained property changes. This method can be called when a constrained property has changed and it will send the appropriate PropertyChangeEvent to any registered VetoableChangeListeners.

This method will migrate to java.awt.Component in the next major JDK release

Throws:
java.beans.PropertyVetoException - when the attempt to set the property is vetoed by the receiver.

addVetoableChangeListener

public void addVetoableChangeListener(java.beans.VetoableChangeListener listener)
Add a VetoableChangeListener to the listener list. The listener is registered for all properties.

This method will migrate to java.awt.Component in the next major JDK release

Parameters:
listener - The VetoableChangeListener to be added

removeVetoableChangeListener

public void removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
Remove a VetoableChangeListener from the listener list. This removes a VetoableChangeListener that was registered for all properties.

This method will migrate to java.awt.Component in the next major JDK release

Parameters:
listener - The VetoableChangeListener to be removed

getTopLevelAncestor

public java.awt.Container getTopLevelAncestor()
Returns the top-level ancestor of this component (either the containing Window or Applet), or null if this component has not been added to any container.
Returns:
the top-level Container which this component is in.

addAncestorListener

public void addAncestorListener(AncestorListener listener)
Registers listener so that it will receive AncestorEvents when it or any of its ancestors move or are made visible / invisible. Events are also sent when the component or its ancestors are added or removed from the Component hierarchy

This method will migrate to java.awt.Component in the next major JDK release

See Also:
AncestorEvent

removeAncestorListener

public void removeAncestorListener(AncestorListener listener)
Unregisters listener so that it will no longer receive AncestorEvents

This method will migrate to java.awt.Component in the next major JDK release

See Also:
addAncestorListener

addNotify

public void addNotify()
Notification to this component that it now has a parent component. When this method is invoked, the chain of parent components is set up with KeyboardAction event listeners.
Overrides:
addNotify in class java.awt.Container
See Also:
registerKeyboardAction

removeNotify

public void removeNotify()
Notification to this component that it no longer has a parent component. When this method is invoked, any KeyboardActions set up in the the chain of parent components are removed.
Overrides:
removeNotify in class java.awt.Container
See Also:
registerKeyboardAction

repaint

public void repaint(long tm,
                    int x,
                    int y,
                    int width,
                    int height)
Adds the specified region to the dirty region list if the component is showing. The component will be repainted after all of the currently pending events have been dispatched.
Overrides:
repaint in class java.awt.Component
See Also:
isShowing, addDirtyRegion

repaint

public void repaint(java.awt.Rectangle r)
Adds the specified region to the dirty region list if the component is showing. The component will be repainted after all of the currently pending events have been dispatched.
See Also:
isShowing, addDirtyRegion

revalidate

public void revalidate()
Support for deferred automatic layout.

Calls invalidate() and then adds this components validateRoot to a list of components that need to be validated. Validation will occur after all currently pending events have been dispatched. By default only JScrollPane.isValidateRoot() returns true. In other words after this method is called, the first JScrollPane that contains this component (if any) will be validated.

See Also:
invalidate, validate, isValidateRoot, addInvalidComponent

isValidateRoot

public boolean isValidateRoot()
If this method returns true, revalidate() calls by descendants of this component will cause the entire tree beginning with this root to be validated. Returns false by default. JScrollPane overrides this method and returns true.
Returns:
false
See Also:
revalidate, invalidate, validate

isOptimizedDrawingEnabled

public boolean isOptimizedDrawingEnabled()
Returns true if this component tiles its children, i.e. if it can guarantee that the children will not overlap. The repainting system is substantially more efficient in this common case. JComponent subclasses that can't make this guarantee, e.g. JLayeredPane, should override this method to return false.
Returns:
true if this components children don't overlap

paintImmediately

public void paintImmediately(int x,
                             int y,
                             int w,
                             int h)
Paint the specified region in this component and all of its descendants that overlap the region, immediately.

It's rarely neccessary to call this method. In most cases it's more efficient to call repaint which defers the actual painting and can collapse redundant requests into a single paint call. This method is useful if one needs to update the display while the current event is being dispatched.

See Also:
repaint

paintImmediately

public void paintImmediately(java.awt.Rectangle r)
Paint the specified region now.

This method will migrate to java.awt.Component in the next major JDK release


setDoubleBuffered

public void setDoubleBuffered(boolean aFlag)
Set whether the receiving component should use a buffer to paint. If set to true, all the drawing from this component will be done in an offscreen painting buffer. The offscreen painting buffer will the be copied onto the screen. Swing's painting system always use a maximum of one double buffer. If a Component is buffered and one of its ancestor is also buffered, the ancestor buffer will be used.

isDoubleBuffered

public boolean isDoubleBuffered()
Return whether the receiving component should use a buffer to paint.
Overrides:
isDoubleBuffered in class java.awt.Component

getRootPane

public JRootPane getRootPane()
Returns the JRootPane ancestor for a component
Returns:
the JRootPane that contains this component, or null if no JRootPane is found

Overview | Package | Class | Tree | Deprecated | Index | Help Java Platform
1.1.7
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Submit a bug or feature
Submit comments/suggestions about javadoc
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.